import request from "../../http/request";
import {DynamicRoutes,BusinessDynamicRoutes} from "../../router";
import {getToken} from "../../utils/auth";
import store from "../../store";

//登录接口
export function login(phone, password){
    return request.post('/api/user/login',{phone,password});
    // return new Promise((resolve,reject) => {
    //     const resp = {
    //         status:200,
    //         token:'qwer'
    //     }
    //     if (username==="admin" && password==="admin"){
    //         resolve(resp)
    //     }
    //     reject()
    // })
}

// 获取用户信息
export function getInfo(){
    let url="/api/user/getUser";
    return request.get(url,{
        headers:{
            Token:getToken()
        }
    })
    // return new Promise((resolve, reject) => {
    //     const resp = {
    //         roles:["admin"],
    //         user:{
    //             username:'admin',
    //             name:'万能的魔术菇',
    //             avatar:'https://img2.baidu.com/it/u=3644579383,1360526475&fm=26&fmt=auto'
    //         }
    //     }
    //     resolve(resp)
    // })
}

// 获取用户的路由
export function getRoutes(){
    return new Promise((resolve, reject) => {
        let user = store.getters.userInfo
        let routes = []
        if (user.phone == 'admin'){
            routes = DynamicRoutes;
        }else {
            routes = BusinessDynamicRoutes
        }
        // const routes = BusinessDynamicRoutes
        resolve(routes)
    })
}
